home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15628 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: wbporter@aol.com (Wbporter)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: 8 Queens prog help
  5. Date: 20 Apr 1996 10:41:19 -0400
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4lat2f$pk4@newsbf02.news.aol.com>
  9. References: <4l87ud$73u@solutions.solon.com>
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11. X-Newsreader: AOL Offline Reader
  12.  
  13. >Need some C help this week.  I'm currently working on a program 
  14. >called "Eight Queens".  Basically, I have to place 8 queen chess 
  15. >pieces on an 8x8 chess board without them checking one another.  
  16.  
  17. You don't need a 2-d array for the board, but four linear arrays would
  18. come in
  19. handy, defined globally so that all recursive searches can use them.  One
  20. would use
  21. the file as subscript to hold the rank you are working on.  The other
  22. three would
  23. hold zeros until a queen had been placed.  The subscripts would be (in
  24. turn)
  25. the rank, SUM of rank and file, and DIFFERENCE of rank and file (plus
  26. constant
  27. to prevent a negative value).  If you don't find a 1 at any of those array
  28. locations
  29. after calculating the subscripts, place 1 there and either do the next
  30. recursion
  31. (next file) or display a solution.  If you successfully place a queen at
  32. any point,
  33. zero the appropriate place in each array before moving on.
  34.  
  35. The sum and difference arrays will handle conflicts on the diagonals and
  36. the rank 
  37. array is self explanatory.  The fact you can only do one subscript at a
  38. time takes
  39. care of conflicts on the file.   Hope this helps.
  40.  
  41.